<?php

/**
 * Just sugar
 */
class Html {

    public static function includeJs(/* files */) {

        $args = func_get_args();

        $arrIncludes = array_map(create_function('$func', '
            return "<sctipt type=\"text/javascript\"  src=\"$func\"></script>";
        '), $args);

        return implode($arrIncludes);
    }

    public static function a($link, $text, $className = null) {
        return self::element('a', array(
            'href' => $link,
            'class' => $className,
        ), $text);
    }

    public static function li($content, $className = null) {
        return self::simpletag('li', $content, $className);
    }

    public static function ol(array $arr, $className = null) {
        return self::simpletag('ol', implode('', array_map(array('self', 'li'), $arr) ), $className );
    }

    public static function ul(array $arr, $className = null) {
        return self::simpletag('ul', implode('', array_map(array('self', 'li'), $arr) ), $className );
    }

    public static function trOfTh(array $arr, $className = null) {
        return self::simpletag('tr', implode('', array_map(array('self', 'th'), $arr) ), $className );
    }

    public static function tr(array $arr, $className = null) {
        return self::simpletag('tr', implode('', array_map(array('self', 'td'), $arr) ), $className );
    }

    public static function td($content, $className = null) { return self::simpletag('td', $content,$className); }
    public static function th($content, $className = null) { return self::simpletag('th', $content, $className); }

    public static function span($content, $className = null) { return self::simpletag('span', $content, $className); }
    public static function div($content, $className = null)  { return self::simpletag('div', $content, $className); }
    public static function p($content, $className = null)    { return self::simpletag('p', $content, $className); }

    public static function h1($content, $className = null) { return self::simpletag('h1', $content, $className); }
    public static function h2($content, $className = null) { return self::simpletag('h2', $content, $className); }
    public static function h3($content, $className = null) { return self::simpletag('h3', $content, $className); }
    public static function h4($content, $className = null) { return self::simpletag('h4', $content, $className); }
    public static function h5($content, $className = null) { return self::simpletag('h5', $content, $className); }

    public static function img($src, $width = null, $height = null, $alt = '', $className = null) {
        return self::element('img', array(
            'src' => $src,
            'width' => $width,
            'height' => $height,
            'alt' => $alt,
            'class' => $className,
        ));
    }

    public static function button($value, $onclick = null, $name = null) {
        return self::element('input', array(
            'type' => 'button',
            'value' =>$value,
            'name' => $name,
            'onclick' => $onclick,
        ));
    }

    //////
    private static function simpletag($tag, $content, $className) {
        return self::element($tag, array(
            'class' => $className,
        ), $content);
    }

    public static function element($tag, array $hAttlist = array(), $content = null) {

        $attributes = '';

            foreach ($hAttlist as $name => $value) {
            $attributes .= ($value === null) ?
                '' :
                ' ' . $name . '="' . strtr( trim($value), array('"' => '\'')) . '"';
        }

        return  '<' . $tag . $attributes .
            (($content === null) ? ' />' : '>' . $content . '</' . $tag . '>');
    }

}

?>